package com.qq.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qq.bean.Chatrecord;
import com.qq.service.ChatrecordService;
import com.qq.service.impl.ChatrecordServiceImpl;

@MultipartConfig
@WebServlet("/ChatrecordServlet.do")
public class ChatrecordServlet extends HttpServlet{
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ChatrecordService cs = new ChatrecordServiceImpl();
		String myAccount = req.getParameter("myAccount");
		//System.out.println(myAccount);
		String friendAccount = req.getParameter("friendAccount");
		List<Chatrecord> ourMsg = cs.selectMessageForMyfriend(myAccount, friendAccount);
		System.out.println(ourMsg);
		ObjectMapper mapper = new ObjectMapper();
		String json = mapper.writeValueAsString(ourMsg);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(json);
		System.out.println(json);
		System.out.println(ourMsg);
	}
}
